#ifndef VMPAGE_H_
#define VMPAGE_H_

/*
Copyright (C) 2011 Salil Bhagurkar

This file is part of illusion

illusion is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

illusion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with illusion.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <arch/page.h>
#include <kernel/page.h>

#define MAP_UPDATE_PHYS 1
#define MAP_UPDATE_FLAGS 2
#define MAP_CREATE 4

struct vmmap {
	//Pointer to the processor's page mapping system
	struct page_sys page_sys;
	//Is set if the page_sys is currently active
	bool is_online;
	//TODO Need to map more pages dynamically. Right now this does only 4096 pages
	u32 vm_pagemap[NR_WORDS];
	//Page map start address. 0 for kernel
	void *vm_pagemap_start;
};

void vm_set_map_trans(uint_t the_trans);
uint_t vm_get_map_trans();
void vm_map_address(struct vmmap *vmmap, void *phys, void *vaddr, u32 page_flags);
void vm_unmap_address(struct vmmap *vmmap, void **was_phys, void *vaddr);
int vm_is_page(struct vmmap *vmmap, void *vaddr);
/*Reserve VM page*/
void vm_reserve_page(struct vmmap *vmmap, void *vaddr);
void vm_reserve_pages(struct vmmap *vmmap, void *vaddr, uint_t count);
void *virt_to_phys(struct vmmap *vmmap, void *virt_address);
int vm_free_pages(struct vmmap *vmmap, void *virt_address, uint_t count);
void *vm_get_virt(struct vmmap *vmmap, uint_t count);
void vm_free_virt(struct vmmap *vmmap, void *addr, uint_t count);
void *vm_get_pages(struct vmmap *vmmap, uint_t count, u32 page_flags);
void *vm_get_virt_for_phys(struct vmmap *vmmap, void *phys, uint_t count, u32 page_flags);
void vm_make_phys_for_virt(struct vmmap *vmmap, void *vaddr, uint_t count, u32 page_flags);
void vm_set_online(struct vmmap *from_vmmap, struct vmmap *vmmap);
void vm_prepare_online(struct vmmap *from_vmmap, struct vmmap *vmmap);
uint_t vm_count_free(struct vmmap *vmmap);
uint_t vm_total_count(struct vmmap *vmmap);

#endif /* VMPAGE_H_ */
